<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        ul {
            display: flex;
        }

        li {
            background-color: aqua;
            color: red;
            padding: 10px 15px;
        }

        li.action {
            background-color: red;
            color: rgb(218, 213, 213);
        }

        .box {
            position: relative;
        }

        .box>div {
            height: 300px;
            border: 1px solid #000;
            display: none;
        }

        .box>div.action {
            display: block;
        }
    </style>
</head>

<body>
    <ul>
        <li class="action">标题1</li>
        <li>标题2</li>
        <li>标题3</li>
        <li>标题4</li>
    </ul>
    <div class="box">
        <div class="action">内容1111</div>
        <div>2222</div>
        <div>3333</div>
        <div>4444</div>
    </div>
    </head>

    <body>
        <script>

            // 添加点击事件
            let lis = document.querySelectorAll('li');
            let divs = document.querySelector('.box').querySelectorAll('div');

            for (let i = 0; i < lis.length; i++) {
                lis[i].setAttribute('index', i); // setAttribute：增加一个指定名称和值的新属性，或者把一个现有的属性设定为指定的值。
                lis[i].onmouseover = function () {
                    for (let j = 0; j < lis.length; j++) {
                        lis[j].className = '';

                    }
                    this.className = 'action';
                    let index = this.getAttribute('index'); // 
                    for (let j = 0; j < divs.length; j++) {
                        divs[j].style.display = 'none';
                    }
                    divs[index].style.display = 'block';
                }
            }
        </script>  
    </body>

</html>